42d94fe229477d9048d9b389a2472ff6f6ff2596,modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheDeploymentManager.java,GridCacheDeploymentManager,onUndeploy0,#ClassLoader#,222

Before Change


     * @param ldr Loader.
     */
    private void onUndeploy0(final ClassLoader ldr) {
        for (final GridCacheContext<K, V> cacheCtx : cctx.cacheContexts()) {
            GridCacheAdapter<K, V> cache = cacheCtx.cache();

            Set<K> keySet = cache.keySet(cacheCtx.vararg(
                new P1<GridCacheEntry<K, V>>() {
                    @Override public boolean apply(GridCacheEntry<K, V> e) {
                        return cacheCtx.isNear() ? undeploy(e, cacheCtx.near()) || undeploy(e, cacheCtx.near().dht()) :
                            undeploy(e, cacheCtx.cache());
                    }

                    /**
                     * @param e Entry.
                     * @param cache Cache.
                     * @return {@code True} if entry should be undeployed.
                     */
                    private boolean undeploy(GridCacheEntry<K, V> e, GridCacheAdapter<K, V> cache) {
                        K k = e.getKey();

                        GridCacheEntryEx<K, V> entry = cache.peekEx(e.getKey());

                        if (entry == null)
                            return false;

                        V v;

                        try {
                            v = entry.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
                        }
                        catch (GridCacheEntryRemovedException ignore) {
                            return false;
                        }
                        catch (IgniteException ignore) {
                            // Peek can throw runtime exception if unmarshalling failed.
                            return true;
                        }

                        assert k != null : "Key cannot be null for cache entry: " + e;

                        ClassLoader keyLdr = U.detectObjectClassLoader(k);
                        ClassLoader valLdr = U.detectObjectClassLoader(v);

                        boolean res = F.eq(ldr, keyLdr) || F.eq(ldr, valLdr);

                        if (log.isDebugEnabled())
                            log.debug("Finished examining entry [entryCls=" + e.getClass() +
                                ", key=" + k + ", keyCls=" + k.getClass() +
                                ", valCls=" + (v != null ? v.getClass() : "null") +
                                ", keyLdr=" + keyLdr + ", valLdr=" + valLdr + ", res=" + res + ']');

                        return res;
                    }
                }));

            Collection<K> keys = new ArrayList<>();

            for (K k : keySet)
                keys.add(k);

            if (log.isDebugEnabled())
                log.debug("Finished searching keys for undeploy [keysCnt=" + keys.size() + ']');

            cache.clearAll(keys, true);

            if (cacheCtx.isNear())
                cacheCtx.near().dht().clearAll(keys, true);

            GridCacheQueryManager<K, V> qryMgr = cacheCtx.queries();

            if (qryMgr != null)
                qryMgr.onUndeploy(ldr);

            // Examine swap for entries to undeploy.
            int swapUndeployCnt = cacheCtx.isNear() ?
                cacheCtx.near().dht().context().swap().onUndeploy(ldr) :
                cacheCtx.swap().onUndeploy(ldr);

            if (cacheCtx.system())
                continue;

            U.quietAndWarn(log, "");
            U.quietAndWarn(
                log,
                "Cleared all cache entries for undeployed class loader [cacheName=" + cacheCtx.namexx() +
                    ", undeployCnt=" + keys.size() + ", swapUndeployCnt=" + swapUndeployCnt +
                    ", clsLdr=" + ldr.getClass().getName() + ']',
                "Cleared all cache entries for undeployed class loader for cache: " + cacheCtx.namexx());
            U.quietAndWarn(
                log,
                "  ^-- Cache auto-undeployment happens in SHARED deployment mode " +
                    "(to turn off, switch to CONTINUOUS mode)");
            U.quietAndWarn(log, "");
        }

        // Avoid class caching issues inside classloader.

After Change


            cacheCtx.near().dht().context().swap().onUndeploy(ldr) :
            cacheCtx.swap().onUndeploy(ldr);

        if (!cacheCtx.system()) {
            U.quietAndWarn(log, "");
            U.quietAndWarn(
                log,
                "Cleared all cache entries for undeployed class loader [cacheName=" + cacheCtx.namexx() +
                    ", undeployCnt=" + keys.size() + ", swapUndeployCnt=" + swapUndeployCnt +
                    ", clsLdr=" + ldr.getClass().getName() + ']',
                "Cleared all cache entries for undeployed class loader for cache: " + cacheCtx.namexx());
            U.quietAndWarn(
                log,
                "  ^-- Cache auto-undeployment happens in SHARED deployment mode " +
                    "(to turn off, switch to CONTINUOUS mode)");
            U.quietAndWarn(log, "");
        }

        // Avoid class caching issues inside classloader.